﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CCH.DAO;
using CCH.Entity;

public partial class _20_2004_1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            sysfunctionDAO dao = new sysfunctionDAO();
            string title = dao.Get_titleName(dao.Get_pathNO(2004, Request["type"]));

            if (Request.QueryString["mode"] == "new")
            {
                this.lab_title.Text = title + " - 新增";
                this.rbl_status.Items[0].Selected = true;
            }
            else
            {
                this.lab_title.Text = title + " - 修改";

                this.hidd_no.Value = Request.QueryString["ID"];

                album data = new albumDAO().Get_album(int.Parse(this.hidd_no.Value));

                this.tbox_desc.Text = data.alb_desc.ConvertToNewLine();
                this.tbox_name.Text = data.alb_name;

                //是否公開
                this.rbl_status.DataBind();
                this.rbl_status.Items.FindByValue(data.alb_status.ToString()).Selected = true;

            }


        }
    }

    protected void Page_LoadComplete(object sender, EventArgs e)
    {
        this.tbox_name.Focus();
    }

    protected void btn_ok_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(this.tbox_name.Text))
        {
            JsUtil.AlertJs(this, "請輸入相簿名稱!");
            return;
        }

        string str = "";
        albumDAO dao = new albumDAO();
        album data;

        if (this.hidd_no.Value == "")
        {
            str = "新增完成!";
            data = new album();
            data.state = "1";
            data.alb_type = int.Parse(Request["type"]);

        }
        else
        {
            str = "修改完成!";
            data = dao.Get_album(int.Parse(this.hidd_no.Value));
        }

        data.alb_name = this.tbox_name.Text;
        data.alb_desc = this.tbox_desc.Text.ConvertToBR();
        data.alb_status = this.rbl_status.SelectedValue;
        data.createuid = new SessionObject().SessionUserID;
        data.createtime = DateTime.Now;

        if (this.hidd_no.Value == "")
        {
            dao.Add_album(data);
        }

        dao.Update();

        JsUtil.UpdateParentJs(this, str);

    }
}